package com.service.sys;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.common.base.BaseService;
import com.entity.sys.SysSafe;
import com.mapper.sys.SysSafeMapper;
import org.springframework.stereotype.Service;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Map;


@Service
public class SysSafeService extends BaseService<SysSafeMapper, SysSafe> {

    /**
     * 设置密码是否过了有效期
     */
    public void getPwdCycle(Map<String,Object> map, LocalDateTime updatePwdTime){
        SysSafe safe = baseMapper.selectList(Wrappers.emptyWrapper()).get(0);
        //获取密码更改周期
        Integer pwdCycle = safe.getPwdCycle();
        //密码有效期，转为天数
        if (updatePwdTime != null){
            Duration between = LocalDateTimeUtil.between(LocalDateTime.now(), updatePwdTime);
            //密码是否过了有效期
            map.put("pwdCycle",false);
            if (pwdCycle!=0 && between.toDays()>=pwdCycle){
                map.put("pwdCycle",true);
            }
        }else {
            map.put("pwdCycle",true);
        }
        map.put("idleTimeSetting",safe.getIdleTimeSetting());
    }

}
